package stu.sup.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import stu.sup.entity.GiveLike;
import stu.sup.entity.GiveLikeExample;
import stu.sup.entity.ProductComment;
import stu.sup.mapper.GiveLikeMapper;
import stu.sup.mapper.ProductCommentMapper;
import stu.sup.service.IGiveLikeService;

import java.util.List;

/**
 * Created by HUAWEI on 2020/6/27.
 */
public class GiveLikeServiceImpl implements IGiveLikeService{
    @Autowired
    GiveLikeMapper giveLikeMapper;
    @Override
    public int updategivelike(ProductComment productComment) {
        GiveLikeExample example=new GiveLikeExample();
        GiveLikeExample.Criteria criteria=example.createCriteria();
        criteria.andCommentIdEqualTo(productComment.getCommentId());
        criteria.andUserIdEqualTo(productComment.getCustomerId());
        List<GiveLike> giveLikes=giveLikeMapper.selectByExample(example);
        int count=0;
        for (GiveLike g:giveLikes){
            g.setLikeUnmber(g.getLikeUnmber()+1);
            count=giveLikeMapper.updateByPrimaryKey(g);
        }
        return count;
    }

    @Override
    public int canalgivelike(ProductComment productComment) {
        GiveLikeExample example=new GiveLikeExample();
        GiveLikeExample.Criteria criteria=example.createCriteria();
        criteria.andCommentIdEqualTo(productComment.getCommentId());
        criteria.andUserIdEqualTo(productComment.getCustomerId());
        List<GiveLike> giveLikes=giveLikeMapper.selectByExample(example);
        int count=0;
        for (GiveLike g:giveLikes){
            g.setLikeUnmber(g.getLikeUnmber()-1);
            count=giveLikeMapper.updateByPrimaryKey(g);
        }
        return count;
    }
}
